< previous page page_228 next page >

Page 228
e10a6a0a59f035e870d90cca05b85fce.gif
        If Not Playing Then Exit For
    Next i
End Sub
Example program PlayFast, shown in Figure 8.1, uses this code to display a series of images as quickly as possible. Select the File menu's Open command to select a series of bitmaps. On the CD-ROM, a file with a name that ends in ''_0.bmp" represents a series of bitmaps. For example, select the file morph_0.bmp to load the series morph_0.bmp, morph_1.bmp, morph_3.bmp, and so forth. The program loads the series of pictures and stores them in the picFrame control array.
The code used by program PlayFast is more complicated than the previous code because it provides extra control options. It allows you to start and stop the animation, run through the frames repeatedly, or play them forward and backward.
This display technique is quite fast. In one test on a 133MHz Pentium processor, program PlayFast displayed 395 frames per second. While this is certainly fast enough to provide smooth animation, it also means the program must display more frames than necessary. The program will run at different speeds on different computers, so the animation may not look right on every computer.
Timer Controls
A timer control lets a program execute code at regular intervals. Because you want to display animation frames at regular intervals, using a timer control is a natural choice.
Set the timer's Interval property to indicate how many milliseconds you want to pass between frames. Whenever the control's Timer event is triggered, display the next frame in the animation. You can use a global variable NextFrame to keep track of the next frame to display.
The following code shows how a program's Timer event handler can present the next frame in the series.
0228-01.jpg
Figure 8.1
Program PlayFast displays images as quickly as it can.

 
< previous page page_228 next page >